<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将真彩色图像转换为调色板图像</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imagetruecolortopalette" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagetruecolortopalette</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">imagetruecolortopalette</span> &mdash; <span class="dc-title">将真彩色图像转换为调色板图像</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagetruecolortopalette-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagetruecolortopalette</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
   , <span class="methodparam"><span class="type">bool</span> <code class="parameter">$dither</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$ncolors</code></span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagetruecolortopalette()</strong></span>
   将一幅真彩色图像转换为调色板图像。本函数的代码原本是从独立的 JPEG
   小组库代码中提取出来的，非常出色。此代码被修改以在结果调色板中保留尽可能多的 alpha
   通道信息以及尽可能多的颜色。但并没有达到期望的效果。通常最好生成真彩色图像输出，这样可以保证得到最高的输出质量。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagetruecolortopalette-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<code class="parameter">image</code></dt>

<dd>
<p class="para">由图象创建函数(例如<span class="function"><a href="imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>)返回的图象资源。</p></dd>

    
     <dt>
<code class="parameter">dither</code></dt>

     <dd>

      <p class="para">
       指明图像是否被抖动（dithered），如果为
   <strong><code>TRUE</code></strong> 则图像将被抖动使图像中的斑点更多但是颜色更接近。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">ncolors</code></dt>

     <dd>

      <p class="para">
       设定调色板中被保留的颜色的最大数目。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagetruecolortopalette-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagetruecolortopalette-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3742">
    <p><strong>Example #1 Converting a true color image to a palette-based image</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;new&nbsp;true&nbsp;color&nbsp;image<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Convert&nbsp;to&nbsp;palette-based&nbsp;with&nbsp;no&nbsp;dithering&nbsp;and&nbsp;255&nbsp;colors<br /></span><span style="color: #0000BB">imagetruecolortopalette</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Save&nbsp;the&nbsp;image<br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'./paletteimage.png'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imagetruecolortopalette-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。</span></p></blockquote>
 </div>

</div></div></div></body></html>